/*
 * GeneratorAnalyzer.h
 *
 *  Created on: Nov 21, 2008
 *      Author: Ryan
 */

#ifndef GENERATORANALYZER_H_
#define GENERATORANALYZER_H_

#include "../../../OOInterface/Interfaces/UnitVisitor.h"

class GeneratorAnalyzer: public OOInterface::UnitVisitor
{
public:
	GeneratorAnalyzer( const OOInterface::ResourceList& list ) :
		_resources(list) {}
	virtual ~GeneratorAnalyzer() {}

	virtual void visitUnit( const OOInterface::Unit& u )
	{
		for( OOInterface::ResourceList::const_iterator resource = _resources.begin(); resource != _resources.end(); ++resource )
		{
			float netGen = u.getResourceGeneration( *resource ) - u.getResourceUpkeep( *resource );
			_generated.insert( std::pair< const OOInterface::Resource, float>( *resource, netGen ) );
			_rating += netGen;

			_rating -= 0.1* u.getResourceCost( *resource );
		}
	}

	virtual void visitAirAspect( const OOInterface::AirAspect& a ) {}
	virtual void visitLandAspect( const OOInterface::LandAspect& a ) {}
	virtual void visitWaterAspect( const OOInterface::WaterAspect& a ) {}

	virtual void visitBuilderAspect( const OOInterface::BuilderAspect& a ) {}
	virtual void visitBuildingAspect( const OOInterface::BuildingAspect& a ) {}
	virtual void visitTransportAspect( const OOInterface::TransportAspect& a ) {}

	virtual void visitReclaimableAspect( const OOInterface::ReclaimableAspect& a ) {}
	virtual void visitResourceExtractorAspect( const OOInterface::ResourceExtractorAspect& a ) {}

	float getResourceGenerated( const OOInterface::Resource& r )
	{
		ResourceMap::const_iterator i = _generated.find( r );
		return i != _generated.end() ? (*i).second : 0.0f;
	}

	float getRating() const { return _rating; }
	void reset() { _rating = 0.0f; _generated.clear(); }

private:
	float _rating;
	ResourceMap _generated;
	const OOInterface::ResourceList& _resources;

};

#endif /* GENERATORANALYZER_H_ */
